package lumis.portal.page.webresource;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lumis.portal.PortalException;
import lumis.portal.page.PageWebResource;
import lumis.portal.stability.StableMinor;

/**
 * An abstract implementation of {@link IPageWebResourceDataProvider}.
 *
 * @version $Revision: 13093 $ $Date: 2011-05-28 18:40:18 -0300 (Sat, 28 May 2011) $
 * @since 5.0.0
 */
@StableMinor(version = "6.0", sinceVersion = "5.0")
public abstract class AbstractPageWebResourceDataProvider implements IPageWebResourceDataProvider
{
	/**
	 * The page web resource this provider is generating data for.
	 * @since 5.0.0
	 */
	protected PageWebResource pageWebResource;

	/**
	 * Sets {@link #pageWebResource} attribute with the given pageWebResource object.
	 * @since 5.0.0
	 */
	public void init(PageWebResource pageWebResource) throws PortalException
	{
		this.pageWebResource = pageWebResource;
	}

	/**
	 * Template method for filling up a page web resource data properties. 
	 * Calls {@link #getTitle()}, {@link #getDescription()} and
	 * {@link #getKeywords()}.
	 * @since 5.0.0
	 */
	public PageWebResourceData getPageWebResourceData() throws PortalException
	{
		PageWebResourceData pageWebResourceData = new PageWebResourceData();
		
		pageWebResourceData.setTitle(getTitle());
		pageWebResourceData.setDescription(getDescription());
		pageWebResourceData.setKeywords(getKeywords());
		pageWebResourceData.setMetaTags(getMetaTags());
	
		return pageWebResourceData;
	}

	/**
	 * Returns the title for the page web resource.
	 * @return the title. Must not be <code>null</code>.
	 * @since 5.0.0
	 */
	protected abstract String getTitle() throws PortalException;

	/**
	 * Returns the description for the page web resource.
	 * @return the description.
	 * @since 5.0.0
	 */
	protected abstract String getDescription() throws PortalException;

	/**
	 * Returns the keywords for the page web resource.
	 * @return the keywords. Must not be <code>null</code>, but may be an 
	 * empty list to indicate there are no keywords.
	 * @since 5.0.0
	 */
	protected abstract List<String> getKeywords() throws PortalException;
	
	/**
	 * Returns the meta tags map for the page web resource. 
	 * @return	the meta tags map.
	 * @since 6.0.0
	 */
	protected Map<String, String> getMetaTags() throws PortalException
	{
		return new HashMap<String, String>();
	}
}